package com.lm.shedlock.component;

import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class ReportScheduler {

    // 每 10 秒执行一次
    @Scheduled(cron = "*/10 * * * * *")
    @SchedulerLock(name = "reportTask",
            lockAtMostFor = "PT20S", // 最长锁定时间
            lockAtLeastFor = "PT5S") // 最短锁定时间
    public void generateReport() {
        System.out.println("📊 生成报表任务执行: " + LocalDateTime.now());
        try {
            Thread.sleep(3000); // 模拟耗时任务
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}
